@extends('layouts.layouts')
@section('title')
    <title>上传提现凭证</title>
    <style>
        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }
        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }
    </style>

    <style>
        *{ margin:0; padding:0;}
        /*#box{ margin:50px auto; width:540px; min-height:400px; background:#FF9}*/
        /*#demo{ margin:50px auto; width:540px; min-height:800px; background:#CF9}*/
    </style>
@endsection
@section('content')
    <link rel="stylesheet" type="text/css" href="/lib/imgUpload/diyUpload/css/webuploader.css">
    <link rel="stylesheet" type="text/css" href="/lib/imgUpload/diyUpload/css/diyUpload.css">
    <script type="text/javascript" src="/lib/imgUpload/diyUpload/js/webuploader.html5only.min.js"></script>
    <script type="text/javascript" src="/lib/imgUpload/diyUpload/js/diyUpload.js"></script>
    <div class="content">
        <div class="header" style="margin-bottom:5px;">
            <h1 class="page-title">后台管理</h1>
            <ul class="breadcrumb">
                <li><a href="/apply/withdraw">提现申请</a> </li>
                <li class="active">上传凭证</li>
            </ul>
        </div>
        <form action="/apply/postAgree"  method="post" onsubmit="return false;">
            <div class="main-content">
                <div class="row">
                    <div class="">
                        <div id="demo" style="margin:15px;">
                            <div id="as"></div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <input type="hidden" value="" name="img"/>
                    <input type="hidden" name="id" value="{{$id}}"/>
                    {{csrf_field()}}
                    <p>
                        <button type="button" onclick="uploadEvidence();" class="btn btn-primary btn-lg col-md-offset-5" style="width:120px;background:#286090;color:#fff;">提交</button>
                    </p>
                </div>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        $('#as').diyUpload({
            url:'/apply/upload',
            formData: { _token: '{{csrf_token()}}',apply_id:'{{$id}}'},
            success:function( data ) {
                $("input[name='img']").val(data,data.data.url);
                console.info( data );

            },
            error:function( err ) {
                console.info( err );
            },
            buttonText : '上传凭证',
            chunked:true,
            // 分片大小
            chunkSize:512 * 1024,
            //最大上传的文件数量, 总文件大小,单个文件大小(单位字节);
            fileNumLimit:5,
            fileSizeLimit:500000 * 1024,
            fileSingleSizeLimit:50000 * 1024,
            accept: {}
        });

        function uploadEvidence(){
            var id = $("input[name='id']").val();
            var token = '{{csrf_token()}}';
            var imgVal = $("input[name='img']").val();
            if(imgVal == ''){
                swal('提示','未上传凭证');
                return false;
            }
            $.ajax({
                url:'/apply/postAgree',
                data:{id:id,_token:token},
                type:'POST',
                dataType:'json',
                success:function(data){
                    if(data.code == 0){
                        window.location.href='/apply/withdraw';
                    }else{
                        swal('失败',data.message);
                    }
                }
            });
        }
    </script>
@endsection